package com.dingceng.demo

import android.graphics.Color
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class MainAdapter: BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_main) {

    private val itemColors =
        arrayListOf("#F7D9CB", "#E1E5E9", "#F9E6AC", "#E2DDD8", "#DBDDF9", "#FBE3C3", "#EEBBBA")

    override fun convert(holder: BaseViewHolder, item: String) {
        val tv = holder.getView<TextView>(R.id.tv)
        tv.text = item
        tv.setBackgroundColor(Color.parseColor(getItemRandomColor()))
    }

    private fun getItemRandomColor(): String {
        val i = itemColors.size - 1
        val random = (0..i).random()
        return itemColors[random]
    }
}